    
    
    export function dragger(element){
    
console.log('div:',element)
    // 鼠标按下时开始拖拽
    element.addEventListener("mousedown", (e) => {
        // 计算鼠标在div内的偏移量（防止div跳变到鼠标位置）
        const offsetX = e.clientX - element.getBoundingClientRect().left;
        const offsetY = e.clientY - element.getBoundingClientRect().top;
  
        // 鼠标移动时更新div位置
        const handleMouseMove = (e) => {
            element.style.left = `${e.clientX - offsetX}px`;
            element.style.top = `${e.clientY - offsetY}px`;
        };
  
        // 鼠标松开时停止拖拽
        const handleMouseUp = () => {
          document.removeEventListener("mousemove", handleMouseMove);
          document.removeEventListener("mouseup", handleMouseUp);
        };
  
        // 绑定全局事件（避免鼠标移出div后失效）
        document.addEventListener("mousemove", handleMouseMove);
        document.addEventListener("mouseup", handleMouseUp);
      });
    }